﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class AddMenuTop : System.Web.UI.UserControl
    {
        public int intactivetop, intactiveleft;
        public string pathToCreate;
        public int idnextnew;
        ListItem lt;
        protected void Page_Load(object sender, EventArgs e)
        {
            Cate1.Items.Clear();
            DataTable dt = DAL.DCollector.DBCollector.Instance.CallStored("callstored", "SELECT * FROM tbl_Category WHERE Category_ID2 = 0 AND Category_ID1 > 1 AND Category_ID1 < 20", true);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lt = new ListItem(dt.Rows[i]["Category_Name"].ToString(), dt.Rows[i]["Category_ID1"].ToString());
                Cate1.Items.Add(lt);
            }
        }

        protected void btnAddNews_Click(object sender, EventArgs e)
        {
            int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_Category", "Category_ID1"));
            if (txtName.Text != "")
            {
                if (CKEditorNoidung.Text != "")
                {
                    idnextnew = nextid + 1;
                    int id2 = Convert.ToInt32(Cate1.SelectedValue);
                    string EncodeNoidung = Server.HtmlEncode(CKEditorNoidung.Text);
                    string value = "" + idnextnew + "," + id2 + ",N'" + txtName.Text + "','',N'" + CKEditorNoidung.Text + "' ,1,0,'', 0";
                    List<string> values = new List<string>();
                    values.Add(value);
                    DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Category", "insertonerow", values, false);
                    Response.Redirect("/Admin/Index.aspx?panel=2&sub=1");
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng nhập tóm tắt nội dung')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Bạn vui lòng nhập nội dung tin tức')</script>");
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            Response.Redirect("/Index.aspx?panel=2&sub=1");
        }
    }
}